package com.m3958.firstgwt.server.dao;

import net.sf.json.JSONArray;

import com.m3958.firstgwt.server.model.TableSchema;

public class TableSchemaChangeStrategy extends BaseModelChangeStrategy implements ModelChangeStrategy<TableSchema> {
	
	@Override
	public boolean extraPersistTask(TableSchema model){
		return true;
	}

	@Override
	public boolean extraRemoveTask(TableSchema model) {
		return true;
	}

	@Override
	public boolean extraUpdateTask(TableSchema model,TableSchema newModel){
		
		return true;
	}

	@Override
	public boolean afterPersist(TableSchema model) {
		JSONArray ja = JSONArray.fromObject(model.getSchemaJson());
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<ja.size();i++){
			String dbfName = ja.getJSONObject(i).getString("dbfName"); 
			if(dbfName != null){
				sb.append(dbfName).append(",");
			}
		}
		if(sb.length()>0)sb.deleteCharAt(sb.length()-1);
		model.setFieldNameList(sb.toString());
		return true;
	}
}
